package com.dayuanit.util;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.LinkedList;
import java.util.Properties;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class DateBaseUtil{
	
	private static LinkedList<Connection> conns = new LinkedList<Connection>();
	private static final int COUNT_CONNS = 2;
	private static SqlSessionFactory sqlSessionFactory;

	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			
			InputStream is = DateBaseUtil.class.getClassLoader().getResourceAsStream("mybatis/mybatis-config.xml");
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
			
			System.out.println("connection success");
			
		} catch(Exception e) {
			e.printStackTrace();
		}

		
	}
	
	public static SqlSession getSqlSession(boolean autoCommit) {
		return sqlSessionFactory.openSession(autoCommit);
	}

//	public static synchronized Connection getConn() {
//		return conns.pollFirst();
//	}
//	
//	public static synchronized boolean close(Connection conn) {
//		return conns.offerLast(conn);
//	}
}